package com.kamistoat.meimeistore.product.web;

import com.kamistoat.meimeistore.product.service.SkuInfoService;
import com.kamistoat.meimeistore.product.vo.thymeleaf.skuItem.SkuItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.concurrent.ExecutionException;

/**
 * 商品详情页
 */
@Controller
public class ItemController {

    @Autowired
    SkuInfoService skuInfoService;

    /**
     * 获取商品详情页。返回页面名称，不是JSON，不用@ResponseBody注解
     *
     * @param skuId 目标商品SKUID
     * @param model 用于和前端传递数据
     * @return 前端页面名称
     */
    @GetMapping("/{skuId}.html")
    public String itemPage(@PathVariable("skuId") Long skuId, Model model) throws ExecutionException, InterruptedException {
        System.out.println("查询"+ skuId + "商品详情");
        SkuItemVo skuItemVo = skuInfoService.getSkuItem(skuId);
        model.addAttribute("skuitem", skuItemVo);  // 向前端传递数据
        return "item";
    }
}
